import request from '@/api/config/request'
import { IUserQuery, Profile } from '@/store/modules/user'
import { ApiResponse } from './type'

interface UserLoginData {
  email: string;
  password: string;
}

interface LoginResponseData {
  token: string;
}

export const login = (data: UserLoginData): Promise<ApiResponse<LoginResponseData>> => {
  return request.post(
    '/login',
    data
  )
}

// 获取用户信息
interface UserBody {
  token: string;
}
export const getUserInfo = (data?: UserBody): Promise<ApiResponse<Profile>> => {
  return request.post('/auth/info', data)
}

// 获取用户列表
interface IUsers {
  data: [],
  users: Profile[];
  total: number;
}
export const getUsers = (params: IUserQuery): Promise<ApiResponse<IUsers>> => {
  return request.post('/findAll', params)
}

// 删除用户
export const removeUser = (id: number): Promise<ApiResponse<null>> => {
  return request.delete(`/remove/${id}`)
}

// 添加用户
export const addUser = (data: Profile): Promise<ApiResponse<null>> => {
  return request.post('/add', data)
}

// 编辑用户
export const updateUser = (id: number, data: Profile): Promise<ApiResponse<null>> => {
  return request.put(`/update/${id}`, data)
}
